package edu.zut.cs.software.example.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 
 * @author chen ming yang 
 *
 *WebMvcConfigurerAdapter 具有跨域能力
 */
@Configuration//声明明WebConfig是全局配置类
public class WebConfig extends WebMvcConfigurerAdapter{
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")//允许访问的路径
					.allowedOrigins("Http://localhost:8080","Http://localhost:8081","null")//请求来源
					.allowedMethods("GET","POST","PUT","OPTIONS","DELETE")//方法
					.allowCredentials(true)//允许携带
					.maxAge(3600);//最大时间
					}
	
	 @Override
	    public void addResourceHandlers(ResourceHandlerRegistry registry) {

	        registry.addResourceHandler("swagger-ui.html")
	                .addResourceLocations("classpath:/META-INF/resources/");

	        registry.addResourceHandler("/templates/**")
	                .addResourceLocations("classpath:/META-INF/resources/templates/");
	    }
}
